<?php
global $framework;
require_once("$framework/template.php");
require_once("$framework/debug.php");
require_once("$framework/../webapp/application/application.php");
/*----- Templates management -----*/

/**
 * get the corresponding $key data from template buffer. 
 * @param $key key of data.
 * @return data from template buffer.
 */

function __template_get($key){
	$template = Template::getInstance();
	__debug("__template_get(): key=[$key]",__FILE__,__LINE__);
	return $template->getParam($key);
}
/**
 * Set a new ket:value into the template buffer.
 * @param $key key of the data
 * @param $value data
 */
function __template_set($key,$value){
	__debug("__template_set(): key=[$key],value=[".print_r($value,true)."]",__FILE__,__LINE__);
	$template = Template::getInstance();
	$template->setParam($key,$value);
}
/**
 * Add the css link line(s) to the template.
 * @param $value
 * @return unknown_type
 */
function __template_css($value){
	$template = Template::getInstance();
	return $template->getCss($value);
}
/**
 * Import all javascript conigurated into the "javascript/api" param from config.ini.
 * @return html &lt;script/&gt; tags to insert into header of template.
 */
function __template_js(){
	$template = Template::getInstance();
	return $template->importJs();
}
/*----- template rendering -----*/
/**
 * rendering of the template $name
 * @param $name path+name of the template.
 */
function __template($name=""){
	$template = Template::getInstance();
	include(dirname($_SERVER['SCRIPT_FILENAME'])."/webapp/themes/".$template->getActive()."/templates/$name.tpl");
}
/**
function _Html::link($action,$type,$id="*"){
	$template = Template::getInstance();
	return $template->link($action,$type,$id);
}*/

/**
 * get the right child template and render it.
 * @return unknown_type
 */
function __templates(){
	$manager=Router::getCurrentManager();
	$manager->renderAction();
	//__template("managers/");
}

/**
 * Run the application (generate page).
 */
function __webapp(){
	$myApp=Application::getInstance();
	$myApp->run();
}
?>